package com.tedu.food.sys.controller;

import com.tedu.food.common.vo.JsonResult;
import com.tedu.food.common.vo.PageObject;
import com.tedu.food.sys.entity.Category;
import com.tedu.food.sys.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/category/")
public class CategoryController {
	@Autowired
	CategoryService categoryService;

	/** 查询类目信息 */
	@RequestMapping("findCategoryObject")
	public JsonResult findCategoryObject(String categoryName, Integer pageCurrent) {
		System.out.println("pageCurrent"+pageCurrent);
		PageObject<Category> list = categoryService.findCategoryObject(categoryName, pageCurrent);
		//System.out.println("PageObject<Category>"+list);
		return new JsonResult(list);
	}

	/** 添加类目信息 */
	@RequestMapping("insertCategoryObject")
	public JsonResult insertCategoryObject(Category category) {
		int result = categoryService.insertCategoryObject(category);
		return new JsonResult("添加成功");
	}

	/** 根据ids删除类目信息 */
	@RequestMapping("deleteCategoryObjectById")
	public JsonResult deleteCategoryObjectById(Integer... ids) {
		System.out.println("controllerIds:"+ids.toString());
		int result = categoryService.deleteCategoryObjectById(ids);
		return new JsonResult("删除成功");
	}

	/** 修改类目信息 */
	@RequestMapping("updateCategoryObject")
	public JsonResult updateCategoryObject(Category category) {
		//System.out.println("controller层"+category);
		int result = categoryService.updateCategoryObject(category);
		return new JsonResult("修改成功");
	}
	@RequestMapping("findCategoryObjectById")
	public JsonResult findCategoryObjectById (Integer id) {
		return new  JsonResult(categoryService.findCategoryObjectById(id));
		
	}

	@GetMapping("doFindAllCategoryGoods")
	public JsonResult doFindAllCategoryGoods(){
		return new JsonResult(categoryService.findAllCategoryGoods());
	}
	@GetMapping("categoryNameIsExists")
	public boolean categoryNameIsExists(String filedValue){
		return categoryService.categoryNameIsExists(filedValue);
	}

}
